
-- 返回多个返回值
function threeDice()
	d1 = math.random(1,6)
	d2 = math.random(1,6)
	d3 = math.random(1,6)
	total = d1+d2+d3
	return d1,d2,d3,total
end

local a,b,c,d = threeDice()
print(a,b,c,d)


-- math 函数
math.randomseed(0)
a = math.random(); -- 默认 [0,1)
print(a)

a = math.random(14); -- 指定 [0,14)
print(a)
assert(a == 2 )

a = math.random(1,14); -- 指定 [0,14)
print(a)
assert(a == 1 )

-- 复杂的调用
function GetMin(t1)
	str = "myValue=math.min("
	for idx,value in ipairs(t1) do
		str = string.format("%s%d%s",str,value,",")
	end
	str = string.sub(str,1,string.len(str)-1)
	str = string.format("%s%s",str,")")
	load (str)()
	print("str is ",str)
	return myValue
end

ta = {4,5,6,7}
v1 = GetMin(ta)
print("the min is",v1)

-- 调用一个字符串格式的语句
local funcStr = "local value = 12 return value"
local res = load(funcStr)()		-- 调用字符串
assert( res == 12 )				-- 返回值 12
assert( value == nil )			-- 局部变量value现在为nil


-- 测试两个函数 是否相等
local a = function() print "a" end
local b = function() print "a" end
assert(a ~= b) -- 肯定是不相等啦

-- 参数个数不定
local funC = function( ... )
	print(...)
	local args = {...} 
	print(#args)
	print(args[1])
end
funC(1,2,3)





